// 引入net模块
const net = require("net");

const port = 3000;
const host = "127.0.0.1";

// 创建连接
const client = net.createConnection(port, host, port);
// 1. 连接server,成功后触发
client.on("connect", () => {
	console.log("1. client is connected");
});

// 2. 请求data, 未传参数为Buffer
client.on("data", (data) => {
  // 3. 返回的
	console.log("2. client get server data:", data.toString());
});

client.end("this is client");

client.on("close", () => {
	console.log("3. client is closed");
});
